package com.miracle.mvplib.base

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

/**
 * created by miracle on 2022/2/11
 * Desc:使用方法：1.继承此抽象类
 *              2.实现自己契约类Contract类中的View接口
 *              3.实现createPresenter()方法
 */
abstract class BaseMvpFragment<T : ViewBinding, P : IPresenter>(val inflater: (inflater: LayoutInflater, container: ViewGroup?, attachToRoot: Boolean) -> T) :
    Fragment(), IView {

    protected lateinit var viewBinding: T

    protected lateinit var mActivity: Activity

    protected var mPresenter: P

    init {
        mPresenter = createPresenter()
    }

    abstract fun createPresenter(): P

    override fun onAttach(context: Context) {
        super.onAttach(context)
        mActivity = requireActivity()
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        viewBinding = inflater(inflater, container, false)
        return viewBinding.root
    }
}